import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Inject, Post, Get, Query } from '@midwayjs/core';
import { GameRoomInfoEntity } from '../../entity/room';
import { GameRoomInfoService } from '../../service/room';
import { BaseSysConfService } from '../../../base/service/sys/conf';
import { UserInfoEntity } from '../../../user/entity/info';

/**
 * game模块-房间信息
 */
@CoolController({
  api: ['delete', 'update', 'info', 'list', 'page'],
  entity: GameRoomInfoEntity,
  service: GameRoomInfoService,
  // 分页查询配置
  pageQueryOp: {
    keyWordLikeFields: ["b.nickName", 'a.userId', 'a.elephantNumber'],
    fieldEq: ['userId', 'elephantNumber'],
    select: ['a.*', 'b.avatarUrl as ownerAvatar', 'b.nickName as ownerNickname', 'c.avatarUrl as memberAvatar', 'c.nickName as memberNickname'],
    join: [
      {
        entity: UserInfoEntity,
        alias: 'b',
        condition: 'a.ownerId = b.id',
        type: 'leftJoin',
      },
      {
        entity: UserInfoEntity,
        alias: 'c',
        condition: 'a.memberId = c.id',
        type: 'leftJoin',
      }
    ]
  },
})
export class AdminGameRoomInfoController extends BaseController {
  @Inject()
  gameRoomInfoService: GameRoomInfoService;

  @Inject()
  baseSysConfService: BaseSysConfService;


  /** 
   * 设置日志保存时间
   */
  @Post('/setKeep', { summary: '房间记录保存时间' })
  public async setKeep(@Body('value') value: number) {
    await this.baseSysConfService.updateVaule('roomKeep', value);
    return this.ok();
  }

  /**
   * 获得日志保存时间
   */
  @Get('/getKeep', { summary: '获得房间记录保存时间' })
  public async getKeep() {
    return this.ok(await this.baseSysConfService.getValue('roomKeep'));
  }
}
